import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILockFindPasswordWindow } from "../../../../modules/interfaces/ILockFindPasswordWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ConfirmProtectInfoSprite } from "./ConfirmProtectInfoSprite";
import { SetPasswordSprite } from "./SetPasswordSprite";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { LockInfoData } from "./LockInfoData";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class LockFindPasswordWindow
    
    export  class LockFindPasswordWindow extends BaseWindow implements ILockFindPasswordWindow
    {
        constructor()
        {
            super();
            setSize(360, 440);
            title = Language.getString(35502);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=ObjCreate.createBg(17, 42, 325, 390, this);
            var loc2=ObjCreate.createBg(90, 50, 180, 25, this, ImagesConst.PopUpMenuOverSkin);
            this._topicTxt = ObjCreate.createTextField("", 155, 55, 200, 20, this);
            this._topicTxt.htmlText = Language.getString(35503);
            this._topicTxt.filters = [];
            this._confirmProtect = new ConfirmProtectInfoSprite();
            this._confirmProtect.x = 30;
            this._confirmProtect.y = 70;
            addChild(this._confirmProtect);
            this._setPw = new SetPasswordSprite();
            this._setPw.setTipsOneTxt();
            this._setPw.x = 30;
            this._setPw.y = 70;
            this._leftTimes = ObjCreate.createTextField("", 110, 375, 200, 20, this);
            this._leftTimes.htmlText = "<font color=\'#ff0000\'></font>";
            this._leftTimes.filters = [];
            this._sureBtn = ObjCreate.createGButton(Language.getString(35227), 90, 400, 70, 25, this);
            this._sureBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnHandler);
            this._cancelBtn = ObjCreate.createGButton(Language.getString(35407), 200, 400, 70, 25, this);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnHandler);
            return;
        }

        /* internal  */onSureBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (this._confirmProtect.parent) 
            {
                this._confirmProtect.answerQuestion();
            }
            else if (this._setPw.parent) 
            {
                loc1 = this._setPw.setPassword();
                if (loc1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LockAnswerSetLock));
                }
            }
            return;
        }

        /* internal  */onCancelBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */removePanel(): void
        {
            if (this._confirmProtect.parent) 
            {
                removeChild(this._confirmProtect);
            }
            else if (this._setPw.parent) 
            {
                removeChild(this._setPw);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (!this._confirmProtect.parent) 
            {
                this.removePanel();
                addChild(this._confirmProtect);
            }
            if (!this._isSetQ) 
            {
                this.setQuestion();
            }
            this.setLeftTimes();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._confirmProtect.resetSprite();
            this._setPw.resetSprite();
            return;
        }

        public setQuestion(): void
        {
            this._confirmProtect.setQuestion();
            this._isSetQ = true;
            return;
        }

        public answerQuestionCorrect(): void
        {
            this.removePanel();
            addChild(this._setPw);
            this._topicTxt.htmlText = Language.getString(35504);
            return;
        }

        public setLeftTimes(): void
        {
            if (LockInfoData.sPlayerLockError == null) 
            {
                return;
            }
            this._leftTimes.htmlText = Language.getStringByParam(35501, LockInfoData.sPlayerLockError.leftSetTimes);
            return;
        }

        /* internal */ /* var */_topicTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_confirmProtect: ConfirmProtectInfoSprite;

        /* internal */ /* var */_setPw: SetPasswordSprite;

        /* internal */ /* var */_sureBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_leftTimes: Object /* flash.text.TextField */;

        /* internal */ /* var */_isSetQ: Boolean=false;
    }
